package org.dromara.datacheck.mytest;

import java.time.LocalDate;
import java.time.YearMonth;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;

public class DateBuilder {

    public static List<String> buildDatesForMonth(String monthStr) {
        // 检查输入是否合法
        if (monthStr == null || monthStr.isEmpty() || !monthStr.matches("\\d{1,2}")) {
            throw new IllegalArgumentException("Invalid month string: " + monthStr);
        }

        int month = Integer.parseInt(monthStr);
        if (month < 1 || month > 12) {
            throw new IllegalArgumentException("Month must be between 1 and 12");
        }

        // 获取当前年份
        int currentYear = LocalDate.now().getYear();

        // 创建 YearMonth 对象
        YearMonth yearMonth = YearMonth.of(currentYear, month);

        // 获取该月的天数
        int daysInMonth = yearMonth.lengthOfMonth();

        // 创建日期格式化器
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/dd");

        // 构建日期列表
        List<String> dates = new ArrayList<>();
        for (int day = 1; day <= daysInMonth; day++) {
            LocalDate date = LocalDate.of(currentYear, month, day);
            dates.add(date.format(formatter));
        }

        return dates;
    }

    public static void main(String[] args) {
        // 测试方法
        List<String> dates = buildDatesForMonth("10");
        dates.forEach(System.out::println);
    }
}
